package com.cljz.makepassenger.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.cljz.makepassenger.R;
import com.cljz.makepassenger.model.net.bean.GetUserInfoBean;
import com.cljz.makepassenger.ui.holder.GroupMemberListHolder;

import java.util.List;

/**
 * Created by apple on 2017/5/13.
 */

public class GroupMemberListAdapter extends RecyclerView.Adapter<GroupMemberListHolder> {
    private Context context;
    private List<GetUserInfoBean.DataBean> groupMemberList;
    private Boolean isOwner;


    public void setData(List<GetUserInfoBean.DataBean> groupMemberList) {
        this.groupMemberList = groupMemberList;
        notifyDataSetChanged();
    }


    public GroupMemberListAdapter(Context context, List<GetUserInfoBean.DataBean> groupMemberList, Boolean isOwner) {
        this.context = context;
        this.groupMemberList = groupMemberList;
        this.isOwner = isOwner;
    }

    @Override
    public GroupMemberListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new GroupMemberListHolder(View.inflate(context, R.layout.item_group_member_list, null));
    }

    @Override
    public void onBindViewHolder(GroupMemberListHolder holder, final int position) {
        holder.setData(groupMemberList, position, isOwner);
        if (onItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemClickListener.onItemClick(groupMemberList.get(position));
                }
            });
            holder.itemView.findViewById(R.id.tv_member_num).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemClickListener.onItemNumClick(groupMemberList.get(position));
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return groupMemberList == null ? 0 : groupMemberList.size();
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(GetUserInfoBean.DataBean dataBean);

        void onItemNumClick(GetUserInfoBean.DataBean dataBean);
    }
}
